package com.oscar.ehome.presenter;

import com.oscar.ehome.bean.pagebean.ClassRoomBean;
import com.oscar.ehome.bean.pagebean.ClassRoomPrombleBean;
import com.oscar.ehome.model.HttpModel;
import com.oscar.ehome.model.HttpModelImple;
import com.oscar.ehome.model.OnHttpListener;
import com.oscar.ehome.view.konwledge.view.KnowSudyView;
import com.oscar.ehome.view.konwledge.view.KnowprombleView;
import com.oscar.ehome.view.konwledge.view.KnowsetView;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/9/20
 * 团队页面
 */

public class KnowelgePresenter extends BasePresenter {

    KnowsetView knowsetView;
    KnowprombleView knowprombleView;
    KnowSudyView knowSudyView;
    HttpModel httpModel;

    public KnowelgePresenter(KnowsetView knowsetView) {
        this.knowsetView = knowsetView;
        httpModel = new HttpModelImple();
    }

    public KnowelgePresenter(KnowprombleView knowprombleView) {
        this.knowprombleView = knowprombleView;
        httpModel = new HttpModelImple();
    }

    public KnowelgePresenter(KnowSudyView knowSudyView) {
        this.knowSudyView = knowSudyView;
        httpModel = new HttpModelImple();
    }

    /**
     * 查看我的问题列表
     *
     * @param token
     */
    public void getMyPrombleList(String token, String pageNo, String pageSize) {
        httpModel.getmyPromble(token, pageNo, pageSize, new OnHttpListener<ClassRoomPrombleBean>() {
            @Override
            public void onSuccess(ClassRoomPrombleBean obj) {
                if (knowsetView != null)
                    knowsetView.myPrombleList(obj);
            }

            @Override
            public void onError(String msg) {
                if (knowsetView != null)
                    knowsetView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (knowsetView != null)
                    knowsetView.erroy();
            }
        });
    }


    /**
     * 查看所有问题列表
     *
     * @param token
     */
    public void getPrombleList(String token, String answerStatus, String pageNo, String pageSize) {
        httpModel.getPrombles(token, answerStatus, pageNo, pageSize, new OnHttpListener<ClassRoomPrombleBean>() {
            @Override
            public void onSuccess(ClassRoomPrombleBean obj) {
                if (knowprombleView != null)
                    knowprombleView.getKnowPrombles(obj);
            }

            @Override
            public void onError(String msg) {
                if (knowprombleView != null)
                    knowprombleView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (knowprombleView != null)
                    knowprombleView.erroy();
            }
        });
    }


    /**
     * 回答问题
     *
     * @param token
     */
    public void answerPrombleList(String token, String questionId, String remarks) {
        httpModel.answePromble(token, questionId, remarks, new OnHttpListener<String>() {
            @Override
            public void onSuccess(String obj) {
                if (knowprombleView != null)
                    knowprombleView.answerPromble(obj);
            }

            @Override
            public void onError(String msg) {

                if (knowprombleView != null)
                    knowprombleView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (knowprombleView != null)
                    knowprombleView.erroy();
            }
        });
    }

    /**
     * 获取我的学习列表
     *
     * @param token
     */
    public void getstudyList(String token, String pageNo, String pageSize) {
        httpModel.getstudyList(token, pageNo, pageSize, new OnHttpListener<ClassRoomBean>() {
            @Override
            public void onSuccess(ClassRoomBean obj) {
                if (knowSudyView != null)
                    knowSudyView.getknowStudyList(obj);
            }

            @Override
            public void onError(String msg) {
                if (knowSudyView != null)
                    knowSudyView.erry(msg);
            }

            @Override
            public void onFailure() {
                if (knowSudyView != null)
                    knowSudyView.erroy();
            }
        });
    }


}
